package x.mybatis.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Map;

/**
 * @author hanjuntao
 * @date 2025/5/9 0009
 */
public class SpringContextUtils implements ApplicationContextAware {
    private static ApplicationContext apt;

    public SpringContextUtils() {
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        apt = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz) {
        return apt.getBean(clazz);
    }

    public static <T> Map<String, T> getBeans(Class<T> clazz) {
        return apt.getBeansOfType(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        return apt.getBean(name, clazz);
    }

    public static String getEnvironmentProperty(String key) {
        return apt.getEnvironment().getProperty(key);
    }

    public static String[] getActiveProfile() {
        return apt.getEnvironment().getActiveProfiles();
    }

    public static ApplicationContext getContext() {
        return apt;
    }
}
